﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PraiseSystem.Domain.Abstract;
using PraiseSystem.Domain.Entities;
using PraiseSystem.WebUI.Models;

namespace PraiseSystem.WebUI.Controllers
{
    public class PraiseController : Controller
    {
        private IPraiseRepository repo;
        public int PageSize = 4;
        
        public PraiseController(IPraiseRepository repository)
        {
            repo = repository;
        }
        // GET: Praise
        public ViewResult List(int page=0)
        {
            //IEnumerable<Praise> praises = repo.Praises.OrderByDescending(p => p.PraiseID).
            //    Skip((page - 1) * PageSize).Take(PageSize);
            PraiseListViewModel result=new PraiseListViewModel
            {
                Praises= repo.Praises.OrderByDescending(p => p.PraiseID).
                Skip((page - 1) * PageSize).
                Take(PageSize),
                PageInfo=new PageInfo
                {
                    CurrentPage =page,
                    ItemsPerPage =PageSize,
                    TotalItems =repo.Praises.Count()
                }
            };

            return View(result);
        }
    }
}